package com.pureut.quality.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.quality.domain.dto.QualityPatrolInspectionDocumentDto;
import com.pureut.quality.domain.vo.PatrolInspectionDocumentVo;
import com.pureut.quality.domain.vo.QualityPatrolInspectionDocumentVo;
import com.pureut.quality.domain.vo.QualitySchemeConfigurationVo;
import com.pureut.quality.service.QualityPatrolInspectionDocumentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 巡检单据控制层
 * Author:C
 * Date:2023/02/10 15:35
 * @DESC
 */
@RestController
@RequestMapping("/quality-patrol-document")
public class QualityPatrolInspectionDocumentController extends BaseController {

    @Resource
    QualityPatrolInspectionDocumentService qualityPatrolInspectionDocumentService;

    /**
     * 巡检单据列表
     */
    @RequiresPermissions("quality:inspecmanage:patrol:list")
    @GetMapping("/list")
    public TableDataInfo getList(QualityPatrolInspectionDocumentVo qualityPatrolInspectionDocumentVo) {
        startPage();
        //查询巡检单据列表
        List<QualityPatrolInspectionDocumentDto> list = qualityPatrolInspectionDocumentService.getFreezeList(qualityPatrolInspectionDocumentVo);
        return getDataTable(list);
    }

    /**
     * 巡检单据新增
     */
    @RequiresPermissions("quality:inspecmanage:patrol:add")
    @PostMapping("/add")
    @Log(title = "巡检单据新增", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated @RequestBody QualityPatrolInspectionDocumentVo qualityPatrolInspectionDocumentVo) throws Exception {
        return toAjax(qualityPatrolInspectionDocumentService.add(qualityPatrolInspectionDocumentVo));
    }

    /**
     * 巡检单据删除
     */
    @RequiresPermissions("quality:inspecmanage:patrol:remove")
    @DeleteMapping("/delete/{ids}")
    @Log(title = "巡检单据删除", businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable("ids") String ids) {
        return toAjax(qualityPatrolInspectionDocumentService.deleteByIds(ids));
    }

    /**
     * 修改
     */
    @RequiresPermissions("quality:inspecmanage:patrol:edit")
    @PutMapping("/update")
    @Log(title = "巡检单据修改", businessType = BusinessType.UPDATE)
    public AjaxResult update(@Validated @RequestBody QualityPatrolInspectionDocumentVo qualityPatrolInspectionDocumentVo) throws Exception {
        return toAjax(qualityPatrolInspectionDocumentService.updatePatrolInspectionDocument(qualityPatrolInspectionDocumentVo));
    }


    /**
     * 获取检验项目数据(新增时)
     */
    @GetMapping("/getItemMessage")
    public AjaxResult getItemMessage(QualitySchemeConfigurationVo qualitySchemeConfigurationVo) {
        return AjaxResult.success(qualityPatrolInspectionDocumentService.getItemMessage(qualitySchemeConfigurationVo));
    }

    /**
     * 样本检验下方列表
     */
    @GetMapping("/getSampleDownList")
    public AjaxResult getSampleDownList(QualitySchemeConfigurationVo qualitySchemeConfigurationVo) {
        return AjaxResult.success(qualityPatrolInspectionDocumentService.getSampleDownList(qualitySchemeConfigurationVo));
    }

    /**
     * 查看单据信息
     */
    @RequiresPermissions("quality:inspecmanage:patrol:query")
    @GetMapping("/view/{id}")
    public AjaxResult getView(@PathVariable("id") Long id) {
        return AjaxResult.success(qualityPatrolInspectionDocumentService.getViewById(id));
    }

    /**
     * 获取检验项目数据(巡检单据新增时)
     */
    @GetMapping("/getPatrolInspectionDocument")
    public AjaxResult getPatrolInspectionDocument(PatrolInspectionDocumentVo patrolInspectionDocumentVo) {
        return AjaxResult.success(qualityPatrolInspectionDocumentService.getPatrolInspectionDocument(patrolInspectionDocumentVo));
    }
}
